package cachex

import (
	"time"

	"gitee.com/workits/pkgs/redisx"
)

type redisCache struct {
}

func NewRedisCache(cfg Config) (Cache, error) {
	if err := redisx.InitCache(cfg.Config); err != nil {
		return nil, err
	}

	return &redisCache{}, nil
}

func (c *redisCache) Set(key, val string, expiration time.Duration) error {
	return redisx.Set(key, val, expiration)
}

func (c *redisCache) SetNoExpiration(key, val string) error {
	return c.Set(key, val, -1)
}

func (c *redisCache) Get(key string) (string, error) {
	return redisx.Get(key)
}

func (c *redisCache) Del(keys ...string) error {
	return redisx.Del(keys...)
}

func (c *redisCache) Clear() error {
	return redisx.FlushDB()
}
